package hdo.app.hdonline;

import hdo.app.hdonline.controllibs.HDOControllibs;
import hdo.app.hdonline.models.CircularImageView;
import hdo.app.hdonline.models.UserInfo;
import hdo.app.hdonline.services.InternetConnectionChecker;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.SlidingDrawer;
import android.widget.SlidingDrawer.OnDrawerCloseListener;
import android.widget.SlidingDrawer.OnDrawerOpenListener;
import android.widget.TextView;

@SuppressLint("NewApi")
public class MainActivity extends Activity {

	ImageView ivHome, ivLogin, ivReg;
	SlidingDrawer drawer;
	Button button, btTest;
	LinearLayout layout;
	CircularImageView civAvata;
	TextView tvUsername, tvUserNames, tvBirthday;
	RelativeLayout rlayout;
	HDOControllibs hdoc;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		if (InternetConnectionChecker.isNetworkConnected(MainActivity.this
				.getApplicationContext())) {
			// FilmDetail fd = new FilmDetail();
			// fd.setType("phim-le");
			// fd.loadData();
			// for (int i = 0; i < 15; i++) {
			// Log.v("thumb", fd.thumb[i] + "");
			// }
			//
			// FilmCat fc = new FilmCat();
			// fc.loadData();
			// Log.v("cat", fc.getName_vi() + "");
			//
			// FilmCountry fco = new FilmCountry();
			// fco.loadData();
			// Log.v("cat", fco.getName_vi() + "");

			// FilmMovie fm = new FilmMovie();
			// fm.setId("5233");
			// fm.loadData();
			// Log.v("test", fm.getImages_poster1() + "");
		}

		tvUsername=(TextView)findViewById(R.id.tvUserName);
		tvUserNames=(TextView)findViewById(R.id.tvUserNames);
		tvBirthday=(TextView)findViewById(R.id.tvBirthday);
		
		rlayout = (RelativeLayout) findViewById(R.id.info);

		drawer = (SlidingDrawer) findViewById(R.id.slidingDrawer);

		button = (Button) findViewById(R.id.handle);

		drawer.animateClose();
		drawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {
			@Override
			public void onDrawerOpened() {
				// TODO Auto-generated method stub
				button.setBackgroundResource(R.drawable.down);
				button.setRotation(180);
			}
		});

		drawer.setOnDrawerCloseListener(new OnDrawerCloseListener() {
			@Override
			public void onDrawerClosed() {
				// TODO Auto-generated method stub
				button.setBackgroundResource(R.drawable.up);
			}
		});

		ivHome = (ImageView) findViewById(R.id.imgHome);
		ivHome.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(MainActivity.this, HotActivity.class);
				startActivity(intent);
			}
		});
		ivReg = (ImageView) findViewById(R.id.register);
		ivLogin = (ImageView) findViewById(R.id.login);
		ivLogin.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(MainActivity.this,
						LoginActivity.class);
				startActivity(intent);
			}
		});

		
		ivReg.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(MainActivity.this,
						RegisterActivity.class);
				startActivity(intent);
			}
		});

		if (hdoc.success==1) {	
			rlayout.setVisibility(View.VISIBLE);
			ivLogin.setVisibility(View.GONE);
			ivReg.setVisibility(View.GONE);
			UserInfo ui=new UserInfo();
			ui.setId(hdoc.id);
			ui.loadData();
			tvUsername.setText(ui.getName());
			tvUserNames.setText(ui.getUsername());
			tvBirthday.setText(ui.getBirthday());
		}else {
			rlayout.setVisibility(View.GONE);
			ivLogin.setVisibility(View.VISIBLE);
			ivReg.setVisibility(View.VISIBLE);
		}
	}
}
